package main.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.hichip.campro.R;

import java.util.List;

import bean.PhotoListItem;

/**
 * Created by lt on 2018\2\23 0023.
 */

public class PhotoListAdapter extends BaseAdapter {
    private Context mContext;
    private List<PhotoListItem> items;

    public PhotoListAdapter(Context context, List<PhotoListItem> items) {
        this.mContext = context;
        this.items = items;
    }

    @Override
    public int getCount() {
        return items.size();
    }

    @Override
    public PhotoListItem getItem(int position) {
        return items.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        PhotoListItem item = getItem(position);
        ViewHolder holder = new ViewHolder();
        if(convertView==null){
            convertView=View.inflate(mContext, R.layout.item_photo_list,null);
            holder.iv_snapshot=convertView.findViewById(R.id.item_snapshot);
            holder.tv_name_num=convertView.findViewById(R.id.item_name_num);
            holder.tv_uid=convertView.findViewById(R.id.item_uid);
            convertView.setTag(holder);
        }else {
            holder= (ViewHolder) convertView.getTag();
        }
        Glide.with(mContext).load(item.getPath()).into(holder.iv_snapshot);
        holder.tv_name_num.setText(item.getNickName()+"("+item.getNum()+")");
        holder.tv_uid.setText(item.getUid());


        return convertView;
    }


    private class ViewHolder {
        ImageView iv_snapshot;
        TextView  tv_name_num;
        TextView  tv_uid;

    }
}
